//
//  TagCell.m
//  jipin
//
//  Created by lcb on 5/15/15.
//  Copyright (c) 2015 liuchengbin. All rights reserved.
//

#import "TagCell.h"

#import "AOTag.h"

@interface TagCell ()<AOTagDelegate>
{
    
}
@property (nonatomic, strong) AOTagList *tagList;
@property(nonatomic,strong) UIView *bgView;
@end
@implementation TagCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.backgroundColor=[UIColor clearColor];
        _bgView =[[UIView alloc] initWithFrame:self.bounds];
        _bgView.backgroundColor=[UIColor clearColor];
        [self.contentView addSubview:_bgView];
        _tagList = [[AOTagList alloc] initWithFrame:CGRectMake(0, 0, DEVICE_WIDTH-PHOTO_TIME_PADDING*2, 80)];
        _tagList.backgroundColor =[UIColor clearColor];
        _tagList.delegate=self;
        [_bgView addSubview:_tagList];
        
    }
    return self;
}
-(void)dealloc
{
    self.bgView =nil;
    self.data=nil;
    self.key=nil;
    self.tagList.delegate =nil;
    self.tagList=nil;
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgView.frame=self.bounds;
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSArray *tagAr =(NSArray *)model;
    self.data =model;
    self.indexPath =indexPath;
    float fTop = [self.tagList addTags:tagAr limitLine:3 type:@"TagCell"];
    _tagList.frame =CGRectMake(PHOTO_TIME_PADDING, 0, DEVICE_WIDTH-PHOTO_TIME_PADDING*2,fTop);
    [self layoutSubviews];
}
/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    NSArray *tagAr =(NSArray *)model;
    TagCell *tc =[[TagCell alloc] init];
    float fTop = [tc.tagList addTags:tagAr limitLine:3 type:@"TagCell"];
    tc=nil;
    return fTop;
}
- (void)tagDidSelectTag:(AOTag *)tag
{
    if (self.actionBlock) {
        NSDictionary *dictionary=nil;
        if ([tag.tTitle isEqualToString:@"更多"]) {
            dictionary=[NSDictionary dictionaryWithObject:@"更多" forKey:@"title"];
        }else
        {
            for (NSDictionary *datat in self.data) {
                NSString *title =[datat objectForKey:@"title"];
                if ([title isEqualToString:tag.tTitle]) {
                    dictionary = datat;
                    break;
                }
            }
        }
        
       self.actionBlock(BEventType_tag,self,dictionary,nil,self.indexPath);
    }
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
@end
